//
//  AFSoundManagerViewController.m
//  myDemo2
//
//  Created by wuxueying on 14-4-30.
//
//

#import "AFSoundManagerViewController.h"
#import "AFSoundManager.h"

@interface AFSoundManagerViewController ()
@property (weak, nonatomic) IBOutlet UILabel *timeGo;
@property (weak, nonatomic) IBOutlet UILabel *timeALL;
@end
@implementation AFSoundManagerViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (IBAction)playLocal:(id)sender {
    [[AFSoundManager sharedManager]startPlayingLocalFileWithName:@"jazz.mp3" andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"mm:ss"];
        
        NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
        _timeGo.text = [formatter stringFromDate:elapsedTimeDate];
        
        NSDate *timeRemainingDate = [NSDate dateWithTimeIntervalSince1970:timeRemaining];
        _timeALL.text = [formatter stringFromDate:timeRemainingDate];
    }];
}

- (IBAction)playRemote:(id)sender {
    [[AFSoundManager sharedManager]startStreamingRemoteAudioFromURL:@"http://www.royaltyfreemusic.com/music_clips/free/Big_Blue_Jam_2.mp3" andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"mm:ss"];
        
        NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
        _timeGo.text = [formatter stringFromDate:elapsedTimeDate];
        
        NSDate *timeRemainingDate = [NSDate dateWithTimeIntervalSince1970:timeRemaining];
        _timeALL.text = [formatter stringFromDate:timeRemainingDate];
    }];
}

@end
